package com.z100h.supplychain.evidence.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.jeeplus.common.config.Global;
import com.jeeplus.core.persistence.Page;
import com.jeeplus.core.service.CrudService;
import com.z100h.supplychain.evidence.entity.WarehouseReceipt;
import com.z100h.supplychain.evidence.entity.WarehouseReceiptVO;
import com.z100h.supplychain.evidence.mapper.WareReceiptMapper;

/**
 * 入库单service
 */
@Service
@Transactional(readOnly = true)
public class WarehouseReceiptService extends CrudService<WareReceiptMapper, WarehouseReceipt> {

	@Autowired
	private WareReceiptMapper wareReceiptMapper;

	/**
	 * 保存或者修改
	 * @param warehouseReceipt
	 * @return
	 */
	@Override
	@Transactional(readOnly = false)
	public void save(WarehouseReceipt warehouseReceipt) {
		try {
			wareReceiptMapper.addWarehouseReceipt(warehouseReceipt);
		} catch (Throwable e) {
			logger.error("save is error", e);
		}
	}

	/**
	 * 获取入库单明细
	 * @param warehouseReceipt
	 * @return
	 */
	@Transactional(readOnly = true)
	public WarehouseReceipt getWarehouseReceipt(WarehouseReceipt warehouseReceipt) {
		return wareReceiptMapper.getWarehouseReceipt(warehouseReceipt);
	}

	/**
	 * 查询列表
	 * @param page
	 * @param warehouseReceipt
	 * @return
	 */
	@Transactional(readOnly = true)
	public Page<WarehouseReceipt> findWarehouseReceiptByPage(Page<WarehouseReceipt> page,
			WarehouseReceipt warehouseReceipt) {
		return super.findPage(page, warehouseReceipt);
	}

	/**
	 * 入库下载打码
	 * @param warehouseReceipt
	 * @return
	 */
	@Transactional(readOnly = true)
	public List<WarehouseReceiptVO> findWarehouseReceiptToResourceByExcel(WarehouseReceipt warehouseReceipt) {
		return wareReceiptMapper.findWarehouseReceiptToResourceByExcel(warehouseReceipt,Global.getRfidLength(),Global.getRfidPrefix(),Global.getRfidQrcodeUrl());
	}

	@Transactional(readOnly = true)
	public void updateWarehouseReceipt(WarehouseReceipt warehouseReceipt) {
		warehouseReceipt.preUpdate();
		wareReceiptMapper.updateWarehouseReceipt(warehouseReceipt);
	}

}
